# Makefile for scripts
#
# This file is part of DRBD by Philipp Reisner & Lars Ellenberg.
#
# Copright 2001-2008 LINBIT Information Technologies
# Philipp Reisner, Lars Ellenberg
#
# drbd is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# drbd is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with drbd; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#
# for Debian:
#   update-rc.d drbd defaults 70 08
#

# variables set by configure
DISTRO = @DISTRO@
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
datadir = @datadir@
sbindir = @sbindir@
sysconfdir = @sysconfdir@
systemdunitdir = @systemdunitdir@
tmpfilesdir = @tmpfilesdir@
udevrulesdir = @udevrulesdir@
initscripttype = @initscripttype@
BASH_COMPLETION_SUFFIX = @BASH_COMPLETION_SUFFIX@
UDEV_RULE_SUFFIX = @UDEV_RULE_SUFFIX@
INITDIR = @INITDIR@
LIBDIR = @prefix@/lib/@PACKAGE_TARNAME@
LN_S = @LN_S@

# features enabled or disabled by configure
WITH_UDEV = @WITH_UDEV@
WITH_XEN = @WITH_XEN@
WITH_PACEMAKER = @WITH_PACEMAKER@
WITH_HEARTBEAT = @WITH_HEARTBEAT@
WITH_RGMANAGER = @WITH_RGMANAGER@
WITH_BASHCOMPLETION = @WITH_BASHCOMPLETION@
WITH_83_SUPPORT = @WITH_83_SUPPORT@
WITH_84_SUPPORT = @WITH_84_SUPPORT@
WITH_WINDRBD = @WITH_WINDRBD@


SYSTEMD_TEMPLATES  = drbd-services@.target
SYSTEMD_TEMPLATES += drbd-promote@.service
SYSTEMD_TEMPLATES += drbd-demote-or-escalate@.service
SYSTEMD_TEMPLATES += ocf.ra@.service
SYSTEMD_TEMPLATES += drbd-reconfigure-suspend-or-error@.service

SYSTEMD_TEMPLATES += drbd@.target
SYSTEMD_TEMPLATES += drbd@.service
SYSTEMD_TEMPLATES += drbd-lvchange@.service
SYSTEMD_TEMPLATES += drbd-wait-promotable@.service

# variables meant to be overridden from the make command line
ifeq ($(WITH_WINDRBD),yes)
DESTDIR ?=
else
DESTDIR ?= /
endif

all:

install: install-utils install-udev install-xen install-heartbeat install-pacemaker install-rgmanager install-bashcompletion

install-utils:
	install -d $(DESTDIR)$(LIBDIR)
# "sysv" or "both"
ifeq ($(subst both,sysv,$(initscripttype)),sysv)
	install -d $(DESTDIR)$(INITDIR)
	install -m 755 drbd $(DESTDIR)$(INITDIR)/
endif
# yes, debian apparently allows installing both types from the same package
# "systemd" or "both"
ifeq ($(subst both,systemd,$(initscripttype)),systemd)
	install -d $(DESTDIR)$(systemdunitdir)
	install -m 644 drbd.service $(DESTDIR)$(systemdunitdir)/
	install -m 644 $(SYSTEMD_TEMPLATES) $(DESTDIR)$(systemdunitdir)/
	install -d $(DESTDIR)/lib/drbd/scripts
	install -m 755 drbd $(DESTDIR)/lib/drbd/scripts
	install -m 755 drbd-service-shim.sh $(DESTDIR)/lib/drbd/scripts
	install -m 755 drbd-wait-promotable.sh $(DESTDIR)/lib/drbd/scripts
	install -m 755 ocf.ra.wrapper.sh $(DESTDIR)/lib/drbd/scripts
	install -d $(DESTDIR)$(tmpfilesdir)/
	install -m 444 drbd.tmpfiles.conf $(DESTDIR)$(tmpfilesdir)/drbd.conf
endif
	@ if [ ! -e $(DESTDIR)$(sysconfdir)/drbd.conf ]; then \
		install -d $(DESTDIR)$(sysconfdir)/; \
		install -m 644 drbd.conf $(DESTDIR)$(sysconfdir)/; \
		install -d $(DESTDIR)$(sysconfdir)/drbd.d; \
		install -m 644 global_common.conf $(DESTDIR)$(sysconfdir)/drbd.d; \
	fi
	install -d $(DESTDIR)$(sysconfdir)/multipath/conf.d
	install -m 644 multipath/drbd.conf $(DESTDIR)$(sysconfdir)/multipath/conf.d
	install -m 755 outdate-peer.sh $(DESTDIR)$(LIBDIR)
	install -m 755 snapshot-resync-target-lvm.sh $(DESTDIR)$(LIBDIR)
	install -m 755 notify.sh $(DESTDIR)$(LIBDIR)
	install -m 755 stonith_admin-fence-peer.sh $(DESTDIR)$(LIBDIR)
	( set -e ; cd $(DESTDIR)$(LIBDIR) ;\
	  $(LN_S) -f snapshot-resync-target-lvm.sh unsnapshot-resync-target-lvm.sh ;\
	  $(LN_S) -f notify.sh notify-split-brain.sh ;\
	  $(LN_S) -f notify.sh notify-io-error.sh ;\
	  $(LN_S) -f notify.sh notify-pri-on-incon-degr.sh ;\
	  $(LN_S) -f notify.sh notify-pri-lost.sh ;\
	  $(LN_S) -f notify.sh notify-pri-lost-after-sb.sh ;\
	  $(LN_S) -f notify.sh notify-emergency-reboot.sh ;\
	  $(LN_S) -f notify.sh notify-emergency-shutdown.sh ;\
	  $(LN_S) -f notify.sh notify-out-of-sync.sh; )
ifeq ($(DISTRO),debian)
	@ echo "Don't forget to run update-rc.d"
else
	@ echo "Don't forget to run chkconfig"
endif

install-heartbeat:
ifeq ($(or $(subst no,,$(WITH_83_SUPPORT)), $(subst no,,$(WITH_84_SUPPORT))),yes)
ifeq ($(WITH_HEARTBEAT),yes)
	mkdir -p $(DESTDIR)$(sysconfdir)/ha.d/resource.d
	install -m 755 drbddisk $(DESTDIR)$(sysconfdir)/ha.d/resource.d
	install -m 755 drbdupper $(DESTDIR)$(sysconfdir)/ha.d/resource.d
endif
endif

# Do not use $(prefix) for the resource agent. The OCF standard
# explicitly mandates where resource agents must live,
# no matter what prefix is configured to.
install-pacemaker:
ifeq ($(WITH_PACEMAKER),yes)
	install -d $(DESTDIR)$(LIBDIR)
	install -m 755 crm-fence-peer.sh $(DESTDIR)$(LIBDIR)
	install -m 755 crm-fence-peer.9.sh $(DESTDIR)$(LIBDIR)
	( set -e ; cd $(DESTDIR)$(LIBDIR) ;\
	  $(LN_S) -f crm-fence-peer.sh crm-unfence-peer.sh ;\
	  $(LN_S) -f crm-fence-peer.9.sh crm-unfence-peer.9.sh )
	mkdir -p $(DESTDIR)/usr/lib/ocf/resource.d/linbit
	install -m 755 drbd.ocf $(DESTDIR)/usr/lib/ocf/resource.d/linbit/drbd
	install -m 755 drbd-attr $(DESTDIR)/usr/lib/ocf/resource.d/linbit/drbd-attr
	install -m 644 drbd.shellfuncs.sh $(DESTDIR)/usr/lib/ocf/resource.d/linbit/
endif

install-rgmanager:
ifeq ($(WITH_RGMANAGER),yes)
	mkdir -p $(DESTDIR)$(datadir)/cluster
	install -m 755 drbd.sh.rhcs $(DESTDIR)$(datadir)/cluster/drbd.sh
	install -m 644 drbd.metadata.rhcs $(DESTDIR)$(datadir)/cluster/drbd.metadata
	install -d $(DESTDIR)$(LIBDIR)
	install -m 755 rhcs_fence $(DESTDIR)$(LIBDIR)
endif

install-xen:
ifeq ($(WITH_XEN),yes)
	mkdir -p $(DESTDIR)$(sysconfdir)/xen/scripts
	install -m 755 block-drbd $(DESTDIR)$(sysconfdir)/xen/scripts
endif

install-udev:
ifeq ($(WITH_UDEV),yes)
	mkdir -p $(DESTDIR)$(udevrulesdir)
	install -m 644 drbd.rules $(DESTDIR)$(udevrulesdir)/65-drbd.rules$(UDEV_RULE_SUFFIX)
endif

install-bashcompletion:
ifeq ($(WITH_BASHCOMPLETION),yes)
	mkdir -p $(DESTDIR)$(sysconfdir)/bash_completion.d
	install -m 644 drbdadm.bash_completion $(DESTDIR)$(sysconfdir)/bash_completion.d/drbdadm$(BASH_COMPLETION_SUFFIX)
endif

clean:
	rm -f *~
	rm -f datadisk

distclean: clean

uninstall:
# "sysv" or "both"
ifeq ($(subst both,sysv,$(initscripttype)),sysv)
	rm -f $(DESTDIR)$(INITDIR)/drbd
endif
# "systemd" or "both"
ifeq ($(subst both,systemd,$(initscripttype)),systemd)
	rm -f $(DESTDIR)$(systemdunitdir)/drbd.service
endif
	rm -f $(DESTDIR)$(sysconfdir)/ha.d/resource.d/drbddisk
	rm -f $(DESTDIR)$(sysconfdir)/ha.d/resource.d/drbdupper
	rm -f $(DESTDIR)$(sysconfdir)/xen/scripts/block-drbd
	rm -f $(DESTDIR)$(sysconfdir)/bash_completion.d/drbdadm$(BASH_COMPLETION_SUFFIX)
	! test -L $(DESTDIR)/sbin/rcdrbd || rm $(DESTDIR)/sbin/rcdrbd

.PHONY: install uninstall clean distclean
../../configure:
	@echo "please (re-)run ./autogen.sh with appropriate arguments"; exit 1
../../config.status: ../../configure
	@echo "please (re-)run ./configure with appropriate arguments"; exit 1
Makefile.in: ;
Makefile: Makefile.in ../config.status
	cd .. && ./config.status scripts/Makefile

